/**
 * <p>Copyright (c) 2017 深圳市鹏途交通科技有限公司 </p>
 * <p>				   All right reserved. 		     </p>
 * 
 * <p>项目名称 ： 	深圳市国省检日常化监管系统         </p>
 * <p>创建者   :	hey 
 * 
 * <p>描   述  :   TunnelRecordServiceImpl.java for com.pengtu.gsj.service.impl.yh    </p>
 * 
 * <p>最后修改 : $: Sep 18, 2017-2:11:13 PM v 1.0.0	 hey   $ </p>
 * 
*/

package com.pengtu.gsj.service.impl.yh;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.pengtu.gsj.dao.base.Page;
import com.pengtu.gsj.dao.base.QueryFilter;
import com.pengtu.gsj.dao.yh.TunnelRecordDao;
import com.pengtu.gsj.entity.app.Attachment;
import com.pengtu.gsj.entity.yh.TunnelRecord;
import com.pengtu.gsj.service.system.SystemManageService;
import com.pengtu.gsj.service.yh.TunnelRecordService;

/**
 * 
 * TunnelRecordServiceImpl
 * 
 * Sep 18, 2017 2:11:13 PM
 * 
 * @version 1.0.0
 * 
 */
@Service
@Transactional
public class TunnelRecordServiceImpl implements TunnelRecordService {
	@Autowired
	private TunnelRecordDao tunnelRecordDao;
	
	@Autowired
	private SystemManageService systemManageService;
	
	
	
	@Override
	public void saveTunnelRecord(TunnelRecord tunnelRecord){
		tunnelRecordDao.save(tunnelRecord);
	}
	
	@Override
	public Page<TunnelRecord> findTunnelRecord(Page<TunnelRecord> page, final QueryFilter queryFilter){
		return tunnelRecordDao.findPage(page, queryFilter);
	}
	
	@Override
	public TunnelRecord getTunnelRecordById(String id){
		return tunnelRecordDao.get(id);
	}
	
	@Override
	public void  delateTunnelRecord(TunnelRecord tunnelRecord){
		if(tunnelRecord.getAttachments() != null){
			for(Attachment attachment : tunnelRecord.getAttachments()){
				systemManageService.deleteAttachment(attachment);
			}
		}
		tunnelRecordDao.delete(tunnelRecord);
	}

	@Override
	public boolean checkTestYear(String testYear, String id) {
		return tunnelRecordDao.checkProperty("testYear", testYear, id);
	}
}
